home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / windc.exe / SAMPLE3.C < prev    next >
C/C++ Source or Header  |  1991-07-07  |  11KB  |  329 lines

  1. /* sample of POE and help */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <bios.h>
  6. #include "wwindefs.h"                /* window headers */
  7. #include "wwinstpr.h"                /* window structures/prototypes */
  8.  
  9. void LoadLabels();              /* internal subroutines */
  10. int Process();
  11. void NameHelp(unsigned char helpitem);
  12. void ShiftWindow(struct WWinstruc *winptr, unsigned char scan);
  13.  
  14.  
  15. extern WWVIDMEM WWscreenp;             /* pointer to screen memory */
  16. extern unsigned int WWScreenLength;        /* access to WW defaults */
  17. extern unsigned int WWScreenWidth;
  18.  
  19.  
  20. /* define caption window - globally */
  21. struct WWinstruc Caption =
  22.   {"Caption",20,3,10,60, WHITE,BLACK,SLN_BDR,WHITE,BLACK,INV_CSR};
  23.  
  24. /* define the menu window */
  25. struct WWinstruc Name =
  26.   {"Name",4,8,4,63, RED,WHITE,SLN_BDR,WHITE,RED,INV_CSR};
  27.  
  28.  
  29. /* define the points of entry  for the Name window*/
  30.   struct WWinPOE NamePOEs[] ={
  31.                  {2,10,1,BLACK,NC,'1'},   /* titles */
  32.                  {2,20,1,BLACK,NC,'1'},
  33.                  {2,30,1,BLACK,NC,'1'},
  34.                  {2,40,1,BLACK,NC,'1'},
  35.                  {2,50,1,BLACK,NC,'1'},
  36.                  {4,20,20,BLUE,NC,'N'},     /* first name */
  37.                  {5,20,20,BLUE,NC,'N'},     /* last name */
  38.                  {7,20,4,BLACK,NC,'M'},   /* OK */
  39.                  {7,40,8,BLACK,NC,'M'},  /* cancel */
  40.                  {0,0,0,0,0,0} };        /* dummy */
  41.  
  42. main()
  43.   {
  44.   int i, rc;
  45.   WWscreenp = WWCOLMEM;    /* unecessary - color screen memory is default */
  46.   for (i=0;i<27;i++)               /* clear screen */
  47.     printf("                                          "
  48.        "                                          ");
  49.   if ((rc = WWinDef(&Caption)) !=0)       /* set up caption screen */
  50.     {printf("out of memory"); exit(1);}
  51.  
  52.   WWinLoad(&Caption,1,2,NC,NC,"Press F1 for Help",0);
  53.   WWinLoad(&Caption,2,2,NC,NC,"Choose Cancel to exit this program",0);
  54.   WWinPut(&Caption);
  55.   WWinCurSet(&Caption,1,1);             /* set cursor out of the way */
  56.  
  57.   LoadLabels();                   /* put the labels in the window */
  58.   do
  59.     {
  60.     rc = Process();               /* process the window */
  61.     }
  62.   while (rc != 27);
  63.   Caption.Cursor = NRM_CSR;       /* set cursor back to normal */
  64.   WWinCurSet(&Caption,Caption.UseLength,1);  /* restore cursor */
  65.   }
  66.  
  67.  
  68.  
  69.  
  70. void LoadLabels()
  71. /* this function loads the window with labels for the POEs.
  72.  * Each label is followed by a blank and a 2-digit number which
  73.  * is the offset of the beginning of the POE to the beginning of the
  74.  * label.
  75. */
  76.   {
  77.   unsigned char *LabelPOEs[] =
  78.           { " Mr. [ ] 07",    /* POE starts inside the box */
  79.         " Mrs. [ ] 08",
  80.         " Miss [ ] 08",
  81.         " Ms. [ ] 07",
  82.         " Dr. [ ] 07",
  83.         " First Name :  15",
  84.         "  Last Name :  15",
  85.         " OK  01",
  86.         " Cancel  01"};
  87.  
  88.   int i, j, k, rc;
  89.  
  90.   if ((rc = WWinDef(&Name)) !=0)
  91.     {printf("out of memory"); exit(1);}
  92.   /* load labels for every POE up to the dummy */
  93.   for (i=0;(NamePOEs[i].len) != 0;i++)
  94.     {
  95.     k = strlen(LabelPOEs[i]);            /* assigned for easy reading */
  96.     j = atoi(LabelPOEs[i]+(k-2));         /* calc offset */
  97.     WWinLoad(&Name,NamePOEs[i].row, NamePOEs[i].col-j+1,NC,NC,
  98.                             LabelPOEs[i],k-3);
  99.     }/*for i*/
  100.   }
  101.  
  102.  
  103.  
  104. int Process()
  105. /* this function handles the presentation of the POE
  106.  * and any verification
  107. */
  108.   {
  109.   struct WWinRC retcde;
  110.   char titlehold, *Title[5] = {"Mr.","Mrs.","Miss","Ms.","Dr."};
  111.   char firstname[21],secondname[21], fullname[50];
  112.   int i, activeitem, count, error, done;
  113.  
  114.   done = 0;
  115.   activeitem = 1;                   /* start with first item */
  116.   while (!done)                     /* loop till done != 0 */
  117.     {
  118.     WWinPut(&Name);
  119.     do
  120.       {
  121.       retcde = WWinDoPOE(&Name,NamePOEs,activeitem);
  122.       activeitem = retcde.exval;
  123.       if ( (retcde.ascii == 13)                    /* if ENTER key pressed */
  124.        && (NamePOEs[retcde.exval-1].type != 'M') ) /* but not a menu item */
  125.     retcde.ascii = 0;                          /* ignore it */
  126.       if (retcde.scan == 59)
  127.     NameHelp(retcde.exval);                    /* get help */
  128.       if ( ((retcde.stat & 0x03) != 00)       /* Shift key */
  129.     && (retcde.ascii == 0) )              /* control key */
  130.     ShiftWindow(&Name,retcde.scan);
  131.  
  132.       }
  133.     while (retcde.ascii == 0);  /* require OK or ESC or Cancel */
  134.  
  135.     if ( (retcde.ascii == 27)
  136.       || (retcde.exval == 9) )              /* ESC or Cancel - */
  137.       return(27);                           /* get out         */
  138.  
  139.         /* ENTER was pressed - - validate entries */
  140.     error = 0;                  /* start clean */
  141.     /* check titles */
  142.     count = 0;                  /* count number chosen */
  143.     for (i=0;NamePOEs[i].type == '1';i++)
  144.       {
  145.       WWinRead(&Name, NamePOEs[i].row, NamePOEs[i].col, &titlehold, 1);
  146.       if (titlehold != ' ')
  147.     {
  148.     strcpy(fullname,"-");
  149.     strcat(fullname,Title[i]);
  150.     count++;
  151.     }
  152.       }
  153.     if (count != 1)      /* if error, load error msg and set error switch */
  154.       {
  155.       WWinLoad(&Name,8,15,BLUE,NCB,"Choose ONE and only ONE Title  ",0);
  156.       error = 1;
  157.       }
  158.  
  159.     if (!error)        /* continue checking only if no errors */
  160.       {
  161.       /* check names  */
  162.                 /* can't read to a blank becuase names may
  163.                             contain blanks */
  164.       WWinRead(&Name, NamePOEs[5].row, NamePOEs[5].col,
  165.               firstname,NamePOEs[5].len);
  166.       WWinRead(&Name, NamePOEs[6].row, NamePOEs[6].col,
  167.             secondname,NamePOEs[6].len);
  168.       /* strip ending blanks */
  169.       while (firstname[strlen(firstname)-1] == ' ')
  170.     firstname[strlen(firstname)-1] = '\0';
  171.       while (secondname[strlen(secondname)-1] == ' ')
  172.     secondname[strlen(secondname)-1] = '\0';
  173.       /*  must be some non-blanks in the names */
  174.       if ( (firstname[0] == '\0') || (secondname[0] == '\0') )
  175.     {
  176.     WWinLoad(&Name,8,15,BLUE,NCB,"Names may not be blank             ",0);
  177.     error = 1;
  178.     }
  179.       }/* end of name check */
  180.     if (!error)
  181.       {
  182.       WWinLoad(&Name,8,15,Name.BackAttr,NC,
  183.                  "                                   ",0);
  184.       /* construct full name and put on caption screen */
  185.       strcat(fullname," ");
  186.       strcat(fullname,firstname);
  187.       strcat(fullname," ");
  188.       strcat(fullname,secondname);
  189.       strcat(fullname,"-");
  190.       WWinLoad(&Caption,3,3,NC,NC,
  191. "                                                  ",0); /* clear previous */
  192.       WWinLoad(&Caption,3,3,NC,NC,fullname,0);
  193.       WWinPut(&Caption);
  194.       done = 1;
  195.       }
  196.     }/* while not done */
  197.   }/* end  Process */
  198.  
  199.  
  200.  
  201.  
  202.  
  203. void NameHelp(unsigned char helpitem)
  204. /* this function sets up the help windows (first time through),
  205.  * asks you to chhose between general and specific help, and
  206.  * (if specific help requested) provides specific help for the active
  207.  * POE.
  208. */
  209.   {
  210.   /* define the help windows */
  211.   static struct WWinstruc Help[3] = {
  212.     {"ChooseHelp",8,2,11,20, BLUE,WHITE,BLK_BDR,WHITE,BLACK,INV_CSR},
  213.     {"GenHelp",6,15,10,40, BLUE,WHITE,BLK_BDR,WHITE,BLACK,INV_CSR},
  214.     {"DetailHelp",6,10,10,50, BLUE,WHITE,BLK_BDR,WHITE,BLACK,INV_CSR} };
  215.  
  216.   int i, rc, activeitem;
  217.   unsigned int keyin, statin;    /* test input key */
  218.   char scan;                     /* input key scan code */
  219.   struct WWinRC retcde;          /* return code strucuture for DoPOE */
  220.   static char setup_switch = 0;
  221.  
  222.   if (!setup_switch)
  223.     {
  224.     for (i=0;i<3;i++)
  225.       if ((rc = WWinDef(&Help[i])) !=0)    /* set up help screens */
  226.        {printf("out of memory"); exit(1);}
  227.  
  228.     /* load choosehelp window */
  229.     WWinLoad(&Help[0],1,2,NC,NC,"General Help",0);
  230.     WWinLoad(&Help[0],2,2,NC,NC,"Detail Help",0);
  231.  
  232.     /* load genhelp window */
  233.     WWinLoad(&Help[1],1,2,NC,NC," Enter data and choose OK. ",0);
  234.     WWinLoad(&Help[1],3,2,NC,NC,"Try the arrow keys, tab, or shift-tab",0);
  235.     WWinLoad(&Help[1],4,2,NC,NC,"Try the backspace, delete, and insert",0);
  236.     WWinLoad(&Help[1],5,2,NC,NC,"Try choosing two titles",0);
  237.     WWinLoad(&Help[1],6,2,NC,NC,"Try leaving first or last name blank",0);
  238.     WWinLoad(&Help[1],8,2,NC,NC,"Use shift-arrow keys to move windows",0);
  239.     WWinLoad(&Help[1],10,2,NC,NC,"Press ESC to leave help",0);
  240.  
  241.     /* load some of detail w